package com.wswy.wyjk.ui.drawable

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.support.v4.content.ContextCompat
import android.widget.TextView
import com.raft.framework.utils.UICompat
import com.wswy.wyjk.AppContext
import com.wswy.wyjk.R

class OptionDrawable(private val option:String,
                     private val optionChecked:Boolean) : BaseDrawable(){

    private val sw = UICompat.dp2px(1).toFloat()

    private val strokeColor= ContextCompat.getColor(AppContext.getContext(), R.color.strokeColor)

    private val fullColor = ContextCompat.getColor(AppContext.getContext(),R.color.colorPrimary)

    private val textPaint = TextView(AppContext.getContext()).apply {

        textSize = 16f
        setTextColor(ContextCompat.getColor(AppContext.getContext(), R.color.textColorPrimary))

    }.paint



    override fun draw(canvas: Canvas) {

        if (optionChecked){
            //已选中

            paint.color = fullColor
            paint.style = Paint.Style.FILL

            canvas.drawCircle(rectF.centerX(),rectF.centerY(),rectF.width()/2f,paint)

            textPaint.color = Color.WHITE

        }else{
            //未选中

            paint.color = strokeColor
            paint.style = Paint.Style.STROKE
            paint.strokeWidth = sw

            canvas.drawCircle(rectF.centerX(),rectF.centerY(),rectF.width()/2f-sw*2,paint)

        }


        val x = rectF.width()/2f - textPaint.measureText(option)/2f
        val y = rectF.centerY() - textPaint.fontMetrics.top/2f - textPaint.fontMetrics.bottom/2f
        canvas.drawText(option,x,y,textPaint)


    }



}